//
//  KLMWeekDayView.swift
//  KLM_GN
//
//  Created by Nic on 2025/2/20.
//

import UIKit

class KLMWeekDayView: UIView {

    @IBOutlet weak var weekDayLabel: UILabel!
    @IBOutlet weak var iconView: UIImageView!
    @IBOutlet weak var tempLabel: UILabel!
    
    // 初始化方法
    override init(frame: CGRect) {
        super.init(frame: frame)
        commonInit()
    }
    
    required init?(coder: NSCoder) {
        super.init(coder: coder)
        commonInit()
    }
    
    // 加载 XIB 的通用逻辑
    private func commonInit() {
        let bundle = Bundle(for: type(of: self))
        let nib = UINib(nibName: "KLMWeekDayView", bundle: bundle)
        if let view = nib.instantiate(withOwner: self, options: nil).first as? UIView {
            view.frame = bounds
            view.backgroundColor = .clear
            view.autoresizingMask = [.flexibleWidth, .flexibleHeight]
            addSubview(view)
        }
    }
    
    override func layoutSubviews() {
        super.layoutSubviews()
    }

    override func awakeFromNib() {
        super.awakeFromNib()
        
        backgroundColor = .white
        layer.cornerRadius = 5.0
        weekDayLabel.configStyle(font: UIFont(safeName: "PingFangHK-Regular", size: 10), titleColor: rgba(73, 67, 67, 1))
        tempLabel.configStyle(font: UIFont(safeName: "PingFangSC-Semibold", size: 12), titleColor: rgba(32, 28, 28, 1))
        
        
    }
    
    func refresh(day: String, icon: String, temp: String) -> Void {
        weekDayLabel.text = day
        iconView.image = UIImage(named: icon)
        tempLabel.text = temp
    }
    /*
    // Only override draw() if you perform custom drawing.
    // An empty implementation adversely affects performance during animation.
    override func draw(_ rect: CGRect) {
        // Drawing code
    }
    */

}
